home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / compression / xpk / xpkfast.lha / compress2.s < prev    next >
Encoding:
Text File  |  1993-08-21  |  5.0 KB  |  249 lines

  1.     XDEF    _compress_slow
  2.  
  3. ;On entry:
  4. ;    a0 = InBuf
  5. ;    a1 = OutBuf
  6. ;    a2 = HashTab
  7. ;    d0 = InLen
  8.  
  9.     CODE
  10.  
  11. COMPRESSREGS    reg    a3-a6/d1-d7
  12. _compress_slow:
  13.     movem.l    COMPRESSREGS,-(sp)
  14.     move.l    a0,d1
  15.     add.l    d0,d1        ; d1=src+src_len
  16.  
  17.     moveq.l    #$FFFFFFFC,d2
  18.     and.l    d0,d2
  19.     add.l    a1,d2
  20.     move.l    d2,a4        ; a4=(dst+src_len) & ~3
  21.  
  22.     movem.l    a1/a4,-(sp)    ; save dst and dst_end for later use
  23.     
  24.     moveq.l    #1,d0
  25.     swap    d0
  26.     move.l    a2,a6
  27.     add.l    d0,a6
  28. ;;;    lea    $10000(a2),a6    ; a6=hh a6-$10000 == hash
  29.  
  30.     moveq.l    #0,d0
  31.     move.w    #$9FF,d2
  32. hfill:    move.l    d0,(a2)+    ; fill hash with $00000000
  33.     move.l    d0,(a2)+    ; hash is $A00*8 = $5000 longs big
  34.     move.l    d0,(a2)+
  35.     move.l    d0,(a2)+
  36.     move.l    d0,(a2)+
  37.     move.l    d0,(a2)+
  38.     move.l    d0,(a2)+
  39.     move.l    d0,(a2)+
  40.     dbra    d2,hfill    
  41.  
  42.     move.l    a0,a2        ; d0 = 4*hash_fkt(s,s+1,s+2)
  43.     moveq.l    #-1,d0
  44.     move.b    (a2)+,d0
  45.     asl.w    #3,d0
  46.     add.b    (a2)+,d0
  47.     asl.w    #3,d0
  48.     add.b    (a2),d0
  49.     asl.w    #2,d0
  50.  
  51.     move.l    a0,0(a6,d0.l)    ;hash[hash_val]=s
  52.  
  53.     move.l    #$00000FFF,d4
  54.  
  55.     bra.s    entry_point
  56.  
  57.                 ;REGISTER MAP
  58.                 ;============
  59.  
  60. ;    a0 source
  61. ;    a1 destination byte stream    (post increment)
  62. ;    a2 Temporary
  63. ;    a3 work pointer into LZ77-window
  64. ;    a4 destination word stream    (pre decrement)
  65. ;    a5 Temporary
  66. ;    a6 hashtable
  67. ;    a7 Stack pointer. Don't touch!
  68.  
  69. ;    d0 Temporary
  70. ;    d1 End of input
  71. ;    d2 src - 4095
  72. ;    d3 match_offset , match_len
  73. ;    d4 Constant 4095
  74. ;    d5 place to put control word in output
  75. ;    d6 Counter of Controlbits to insert into the control word.
  76. ;    d7 Buffers the current control word.
  77.  
  78. ;;;---------------------------------------------------------------------------
  79.  
  80. newctl:    move.l    d5,a2
  81.     move.w    d7,(a2)        ; write ctrl_word to it's place
  82. entry_point:
  83.     subq.l    #2,a4
  84.     move.l    a4,d5        ; get place to put next ctrl_word
  85.  
  86.     moveq.l    #15,d6        ; reinitialize ctrl_bit_counter
  87.     moveq.l    #-1,d7        ; fill ctrl_word with $FFFF
  88.  
  89. oloop:    move.l    a0,a3        ; wrk=s
  90.     move.l    a0,d2
  91.     sub.l    d4,d2        ; limit = src - 4095
  92.     moveq.l    #2,d3        ; match_ofs,match_len = 0,2
  93.  
  94. iloop:    move.l    a3,d0            ; d0=$00000FFF
  95.     and.l    d4,d0            ; d0=wrk & $00000FFF
  96.     asl.w    #2,d0
  97.     move.l    0(a6,d0.l),a3        ; p=hh[p & $00000FFF]
  98.  
  99.     cmp.l    d2,a3            ; has src reached the limit
  100.     bcs.s    finished_chain        ; is a3 < d2
  101.  
  102.     move.l    a0,a2
  103.     move.l    a3,a5
  104.  
  105. MATCH    MACRO
  106.     cmp.b    (a2)+,(a5)+
  107.     bne.s    \1
  108.     ENDM
  109.     MATCH    iloop    ; 0
  110.     MATCH    iloop    ; 1
  111.     MATCH    iloop    ; 2
  112.     MATCH    mism    ; 3
  113.     MATCH    mism    ; 4
  114.     MATCH    mism    ; 5
  115.     MATCH    mism    ; 6
  116.     MATCH    mism    ; 7
  117.     MATCH    mism    ; 8
  118.     MATCH    mism    ; 9
  119.     MATCH    mism    ;10
  120.     MATCH    mism    ;11
  121.     MATCH    mism    ;12
  122.     MATCH    mism    ;13
  123.     MATCH    mism    ;14
  124.     MATCH    mism    ;15
  125.     MATCH    mism    ;16
  126.     MATCH    mism    ;17
  127.     addq.l    #1,a5    ;18
  128. mism:    move.l    a5,d0
  129.     sub.l    a3,d0
  130.     subq.w    #1,d0        ; d0=match_len
  131.  
  132.     cmp.w    d0,d3
  133.     bcc.s    iloop        ; new match is not longer than old one
  134.     
  135.     move.l    a0,d3
  136.     sub.l    a3,d3        ; d4 = src - wrk = match_ofs
  137.     swap    d3
  138.     move.w    d0,d3        ; match_ofs,match_len is updated.
  139.  
  140.     cmp.b    #18,d3
  141.     bcs.s    iloop        ; match_len < 18
  142.  
  143. finished_chain:
  144.     cmp.b    #3,d3
  145.     bcs.s    do_literal
  146.  
  147.     moveq.l    #18,d0
  148.     sub.b    d3,d0        ; d0=18-match_len
  149.  
  150.     swap    d3
  151.     asl.w    #4,d3
  152.     or.b    d0,d3        ; d3 = OOOOOOOO OOOOLLLL
  153.     
  154.     move.w    d3,-(a4)    ; write copyinfo
  155.  
  156.     swap    d3        ; d3.w = match_len
  157.     subq.w    #1,d3        ; d3 = match_len - 1
  158.  
  159.     rol.w    #1,d7        ; inject a 1 into control word
  160.     bra.s    incsrc
  161.  
  162. do_literal:
  163.     moveq.l    #0,d3        ; d4 = [pseudo]match_len - 1
  164.     move.b    (a0),(a1)+    ; write literal
  165.     add.w    d7,d7        ; inject 0 into ctrl_word
  166.  
  167. incsrc:    addq.l    #1,a0        ; increment src
  168.  
  169.     move.l    a0,a2
  170.     moveq.l    #-1,d0
  171.     move.b    (a2)+,d0
  172.     lsl.w    #3,d0
  173.     add.b    (a2)+,d0
  174.     lsl.w    #3,d0
  175.     add.b    (a2)+,d0
  176.     asl.w    #2,d0        ; d0 = hash_fkt(src[0],src[1],src[2])
  177.  
  178.     move.l    0(a6,d0.l),a2    ; a2 = hash[hash_val]
  179.     move.l    a0,0(a6,d0.l)    ; hash[hash_val] = src
  180.  
  181.     move.l    a0,d0
  182.     and.l    d4,d0
  183.     asl.w    #2,d0
  184.     move.l    a2,0(a6,d0.l)    ; hh[src&$FFF] = src - [old]hash[hash_val]
  185.     dbra    d3,incsrc
  186.  
  187.     cmp.l    a0,d1        ; Has src reached src_end?
  188.     bcs.s    end_compress_loop
  189.     dbra    d6,oloop
  190.     bra    newctl
  191.  
  192. ;;; The rest is copied from compress_fast !!!! FIXME !!!!
  193. ;;; Only the registers are renamed :-(
  194.  
  195. ;;;The main loop ends here.
  196. ;;;---------------------------------------------------------------------------
  197.                 ;FINALIZATION
  198.                 ;============
  199.  
  200. FillControl:            ;Fill the rest of the control word with 0
  201.     add.w    d7,d7        ;0 means literal items.
  202. end_compress_loop:
  203.     dbra    d6,FillControl
  204.  
  205.     move.l    d5,a2
  206.     move.w    d7,(a2)        ;Write it to its output position
  207.  
  208.     movem.l    (sp)+,d6/d7    ; Pop dst and dst_end
  209.  
  210.     ;Copy the literals after the word stream pointed to by a1.
  211.     move.l    a4,d0        ;d0:=Number of Bytes to increase a1
  212.     sub.l    a1,d0        ;till a1 and a4 are equally aligned.
  213.     bcc.s    did_compress
  214.  
  215. ;byte- and wordstream together do exceede the size of the output buffer.
  216.     moveq    #0,d0        ; return 0 to indicate overrun
  217.     bra.s    finish
  218.  
  219. did_compress:
  220.     moveq    #3,d1
  221.     and.w    d0,d1
  222.  
  223.     moveq.l    #0,d0        ;pad a1 up to make a1 and a4 equally aligned.
  224.     bra.s    EFLoop
  225. FLoop:    move.b    d0,(a1)+
  226. EFLoop:    dbra    d1,FLoop
  227.  
  228.     sub.l    a4,d7        ;d7:=size of wordstream
  229.  
  230.     lsr.l    #2,d7
  231.     bcc.s    ECLoop        ;make sure we do the move.l longword aligned.
  232.     move.w    (a4)+,(a1)+
  233. NoWord:    bra.s    ECLoop
  234. CLoopH:    swap    d7
  235. CLoop:    move.l    (a4)+,(a1)+
  236. ECLoop:    dbra    d7,CLoop
  237.     swap    d7
  238.     dbra    d7,CLoopH
  239.  
  240.     move.l    a1,d0
  241.     sub.l    d6,d0            ;d0:=Final output length
  242. finish:    movem.l    (sp)+,COMPRESSREGS
  243.     rts
  244.  
  245. ;;;---------------------------------------------------------------------------
  246.  
  247.     END
  248.  
  249.